package com.yangcb.workrecord.concurrent.pool;

import com.yangcb.workrecord.concurrent.domain.Systemlog;
import com.yangcb.workrecord.concurrent.service.SystemLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * ${DESCRIPTION}
 *
 * @author yangcb
 * @create 2017-09-28 15:03
 **/

//线程池中工作的线程
@Component("dBThread")
@Scope("prototype")//spring 多例
public class DBThread implements Runnable{
    private String msg;
    private Logger log = LoggerFactory.getLogger(DBThread.class);
    @Autowired
    private SystemLogService systemLogService;

    @Override
    public void run() {
        //模拟在数据库插入数据
        Systemlog systemlog = new Systemlog();
        systemlog.setTime(new Date());
        systemlog.setLogdescribe(msg);
        systemLogService.insert(systemlog);
        log.info("insert->" + msg);
    }


    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


}
